<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>生成html结构</title>
		<style>
			img{
				width: 200px;
				height: 200px;
			}
		</style>
	</head>
	<body>
		<button id="btn">生成结构</button>
		<script>
			var btn = document.getElementById("btn");
			let n = 0;
			
			btn.addEventListener('click',function(){
				if(n==0){
					var box = document.createElement('div');
					box.id = "box";
						
					document.body.insertBefore(box,btn);
					var ulElem = document.createElement('ul');
					ulElem.id = "ulElem";
					box.appendChild(ulElem);
					for(let i =0;i<3;i++){
						var liitem = document.createElement('li');
						ulElem.appendChild(liitem);
						liitem.innerHTML = "list item";
					}
					var newimg = document.createElement('img');
					newimg.src= "img/1.jfif";
					box.appendChild(newimg);
					n++;
				}else{
					alert("只能生成一次");
				}
				
			})
		</script>
	</body>
</html>